import 'package:flutter/material.dart';

double toRpx(BuildContext context, double size) {
  double rpx = MediaQuery.of(context).size.width / 750;
  return rpx * size;
}

countToString(int count) {
  if (count <= 0 || count.isNaN || count == null) {
    return 0;
  }
  double f = count / 10000;
  if (f >= 1) {
    return "${f.toStringAsFixed(1)}w";
  } else {
    return count.toString();
  }
}

secondsToFormat(int seconds) {
  if (seconds <= 0 || seconds.isNaN || seconds == null) {
    return 0;
  }
  int h = 0;
  int m = 0;
  int s = 0;
  String hh = "", mm = "", ss = "";
  if (seconds / 60 / 60 >= 1) {
    h = (seconds / 60 / 60).floor();
    m = ((seconds % 3600) / 60).floor();
  } else if (seconds / 60 >= 1) {
    m = (seconds / 60).floor();
  }
  s = seconds % 60;
  if (h < 9) {
    hh = "0$h";
  } else {
    hh = "$h";
  }
  if (m < 9) {
    mm = "0$m";
  } else {
    mm = "$m";
  }
  if (s < 9) {
    ss = "0$s";
  } else {
    ss = "$s";
  }
  return h != 0
      ? "$hh:$mm:$ss"
      : m != 0
          ? "$mm:$ss"
          : "$ss";
}

changeImageUrl(String url) {
  return "https://img.cwiyc.top/" + url.substring(url.lastIndexOf("/"));
}
